<?php
$conn = mysql_connect ( "localhost", "root", "" ) or die ( "can't connect this database" );
mysql_select_db ( "demo_mysql", $conn );
$id = $_GET ['userid'];
if (isset ( $_POST ['ok'] )) {
	if ($_POST ['user'] == NULL) {
		echo "Please enter your username";
	} else {
		$u = $_POST ['user'];
	}
	if ($_POST ['pass'] != $_POST ['repass']) {
		echo "Password and re-password is not correct";
	} else {
		if ($_POST ['pass'] != NULL) {
			$p = $_POST ['pass'];
		}
	}
	$c = $_POST ['class'];
	if ($u && $p && $c) {
		$sql = "update user set username='" . $u . "', password='" . $p . "', class='" . $c . "' where id='" . $id . "'";
		mysql_query ( $sql );
		header ( "location:list.php" );
		exit ();
	} else {
		if ($u && $c) {
			$sql = "update user set username='" . $u . "', class='" . $c . "' where id='" . $id . "'";
			mysql_query ( $sql );
			header ( "location:list.php" );
		}
	}
}
$sql = "select * from user where id='" . $id . "'";
$query = mysql_query ( $sql );
$row = mysql_fetch_array ( $query );
echo $row['name'];
?>
<form action="edit_user.php?userid=<?=$id?>" method=post>
	Class: <select name=class>
		<option value=1> <?if($row[class] == 1) echo "selected"; ?></option>
		<option value=2> <?if($row[class] == 2) echo "selected"; ?></option>
	</select><br /> 
	Username: <input type=text name=user size=20 value="<?php echo $row[username]; ?>" /><br /> 
	Password: <input type=password	name=pass size=20 /> <br /> 
	Re-password: <input type=password name=repass size=20 /><br /> <input type=submit name=ok value="Edit User" />
</form>







